package com.yami.shop.api.controller;

import com.yami.shop.api.config.DateUtil;
import com.yami.shop.api.config.HttpClient;
import com.yami.shop.api.config.ParamBuilder;
import com.yami.shop.api.config.SignHelper;
import com.yami.shop.bean.meituan.*;
import com.yami.shop.common.util.Json;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/shop")
public class TestShopStatusCallbackController {

    @PostMapping("/testShopStatusCallback")
    public  void CheckOrder() throws Exception {
        String appkey = OpenApiConfig.TEST_APP_KEY;
        String secret = OpenApiConfig.TEST_SECRET;
        String res=null;
        ShopStatusResponse request = buildMockRequest(appkey);

        Map<String, String> params = ParamBuilder.convertToMap(request);
        String sign = SignHelper.generateSign(params, secret);
        params.put("sign", sign);
        params.put("appkey",appkey);
        params.put("timestamp",String.valueOf(DateUtil.unixTime()));
        params.put("version","1.0");
        try {
            res = HttpClient.post(RequestConstant.SHOP_STATUS_CALLBACK, params);
            System.out.println("结果为"+res);
        } catch (Exception e) {
            throw e;
        }
    }

    private  ShopStatusResponse buildMockRequest(String appkey) {
        ShopStatusResponse request = new ShopStatusResponse();

        request.setShopId("test_0001");
        request.setStatus(20);

        return request;
    }

}
